package pkg;

public class demo2 {
	public static void main(String[] args) {
		Circle c1 = new Circle(5);
		System.out.println("area of c1: " + String.format("%.2f", c1.getArea()).toString());//保留两位小数
		pillar p1 = new pillar(c1, 4);
		System.out.println("vol of c1*height: " + String.format("%.2f", p1.getVol()).toString());
		
		Square s1 = new Square(3, 4);
		System.out.println("area of s1: " + String.format("%.2f", s1.getArea()).toString());
		pillar p2 = new pillar(s1, 5);
		System.out.println("vol of s1*height:" + String.format("%.2f", p2.getVol()).toString());
	} 
}

interface Geometry {
	double getArea();
}

class pillar {
	Geometry bottom;
	double height;
	public pillar(Geometry bottom, double height) {
		this.bottom = bottom;
		this.height = height;
	}
	
	public double getVol() {
		return bottom.getArea()*height;//返回体积底乘高
	}
}

class Circle implements Geometry {
	double radium;
	public Circle(double radium) {
		this.radium = radium;
	}
	
	public double getRadium() {
		return radium;
	}

	public void setRadium(double radium) {
		this.radium = radium;
	}

	@Override
	public double getArea() {
		return Math.PI * radium *radium;//计算面积
	}
}

class Square implements Geometry {
	double width;
	double length;
	public Square(double width, double length) {
		this.width = width;
		this.length = length;
	}
	public double getWidth() {
		return width;
	}
	public void setWidth(double width) {
		this.width = width;
	}
	public double getLength() {
		return length;
	}
	public void setLength(double length) {
		this.length = length;
	}
	@Override
	public double getArea() {
		return width * length;
	}
}